/**
 * 验证手机号
 * @param {Object} tel
 */
function testPhone(tel){
	var reg = /^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
	 if (reg.test(tel)) {
	     return true;
	 }else{
//			     document.getElementById("telPhone").focus();
	     return false;
	 };
}

/**
 * 获取单选框的值
 * @param {Object} RadioName
 */
function GetRadioValue(RadioName){
    var obj;
    obj=document.getElementsByName(RadioName);
    if(obj!=null){
        var i;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                return obj[i].value;
            }
        }
    }
    return null;
}

/**
 * 验证身份证号码
 * @param {Object} card
 */
function isCardNo(card)
{
   // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
   var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
   if(reg.test(card)){
   		return true;
   }else{
   		return false;
   }

}
/**
 * 验证工商执照号
 * @param {Object} str
 */
function isLicenseNo(str){
	var reg = /\d{15}/;
	if(reg.test(str)){
   		return true;
   }else{
   		return false;
   }
}
/**
 * 验证邮箱（包含@和.）
 * @param {Object} str
 */
function checkEmail(str){
    var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(re.test(str)){
        return true;
    }else{
        return false;
    }
}
/**
 *  邮政编码的验证（开头不能为0，共6位）
 * @param {Object} str
 */
function checkZipcode(str){
	var re= /^[1-9][0-9]{5}$/
    if(re.test(str)){
      	return true;
    }else{
      return false;

    }
}
/**
 * 验证数字(包含小数点)
*/
function checkNum(str){
    var re = /^[0-9]+.?[0-9]*$/;
    if(re.test(str)){
        return true;
    }else{
        return false;
    }
}
/**
 * 验证出生日期(平年日期格式为YYYY-MM-DD的正则表达式)
*/
function checkBirthDate(str){
    var re = /^([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))$/;
    if(re.test(str)){
        return true;
    }else{
        return false;
    }
}
/**
 * 验证数字(正整数)
*/
function checkIntNum(str){
    var re = /^[0-9]*[1-9][0-9]*$/;
    if(re.test(str)){
        return true;
    }else{
        return false;
    }
}
/**
 * 验证非负整数
*/
function checkUnIntNum(str){
    var re = /^\d+$/;
    if(re.test(str)){
        return true;
    }else{
        return false;
    }
}
/**
 * 判断选取的日期是否小于当前日期
*/
function chkDate (pdate) {
	var d = new Date;
	var today = new Date(d.getFullYear (), d.getMonth (), d.getDate ());
	var reg = /\d+/g;
	var temp = pdate.match (reg);
	var foday = new Date (temp[0], parseInt (temp[1]) - 1, temp[2]);
	if (foday >= today){
		return false;
	}
	return true;
}
/**
 * 判断当前日期是否小于等于选取的日期
*/
function chkSmallDate (pdate) {
	var d = new Date;
	var today = new Date(d.getFullYear (), d.getMonth (), d.getDate ());
	var reg = /\d+/g;
	var temp = pdate.match (reg);
	var foday = new Date (temp[0], parseInt (temp[1]) - 1, temp[2]);
	if (foday >= today){
		return true;
	}
	return false;
}
/**
 * 判断当前日期是否大于选取的日期
*/
function chkBigDate (pdate) {
	var d = new Date;
	var today = new Date(d.getFullYear (), d.getMonth (), d.getDate ());
	var reg = /\d+/g;
	var temp = pdate.match (reg);
	var foday = new Date (temp[0], parseInt (temp[1]) - 1, temp[2]);
	if (foday > today){
		return false;
	}
	return true;
}
function showDateTime(str){
    var show_day=new Array('周日','周一','周二','周三','周四','周五','周六');
    var time=new Date(str.replace(/-/g,"/"));
    var year=time.getFullYear();
    var month = time.getMonth()+1;
    var date=time.getDate();
    var day=time.getDay();
    (month<10)&&(month='0'+month);
    (date<10)&&(date='0'+date);
    var now_time=year+'-'+month+'-'+date+' '+show_day[day];
    return now_time;
}
function strlen(str){  
    var len = 0;  
    for (var i=0; i<str.length; i++) {   
		var c = str.charCodeAt(i);   
		//单字节加1   
		if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
		   len++;   
		} else {   
		  len+=2;   
		}   
    }   
    return len;  
}
function getWhetherStr(type) {
	return type==1?"是":"否";
}
function getWhetherValue(str) {
	return str=="是"?1:0;
}
function getMarriedStr(maritalValue) {
	var marriedStr = "单身";
	if (maritalValue == 2) {
		marriedStr = "已婚";
	} else if (maritalValue == 3) {
		marriedStr = "离异";
	} else if (maritalValue == 4) {
		marriedStr = "丧偶";
	}
	return marriedStr;
}
function getMarriedValue(marriedStr) {
	var maritalValue = 1;
	if (marriedStr == "已婚") {
		maritalValue = 2;
	} else if (marriedStr == "离异") {
		maritalValue = 3;
	} else if (marriedStr == "丧偶") {
		maritalValue = 4;
	}
	return maritalValue;
}
function getRelationStr(relationType) {
	var relationStr = "女儿";
	if (relationType == 2) {
		relationStr = "儿子";
	} else if (relationType == 3) {
		relationStr = "继女";
	} else if (relationType == 4) {
		relationStr = "继子";
	} else if (relationType == 5) {
		relationStr = "养女";
	} else if (relationType == 6) {
		relationStr = "养子";
	}
	return relationStr;
}
function getRelationValue(relationStr) {
	var relationType = 1;
	if (relationStr == "儿子") {
		relationType = 2;
	} else if (relationStr == "继女") {
		relationType = 3;
	} else if (relationStr == "继子") {
		relationType = 4;
	} else if (relationStr == "养女") {
		relationType = 5;
	} else if (relationStr == "养子") {
		relationType = 6;
	}
	return relationType;
}

function getPurposeStr(relationType) {
	var relationStr = "旅游";
	if (relationType == 2) {
		relationStr = "商务";
	} else if (relationType == 3) {
		relationStr = "探亲";
	} else if (relationType == 4) {
		relationStr = "访友";
	} else if (relationType == 5) {
		relationStr = "学习";
	}
	return relationStr;
}
function getPurposeValue(relationStr) {
	var relationType = 1;
	if (relationStr == "商务") {
		relationType = 2;
	} else if (relationStr == "探亲") {
		relationType = 3;
	} else if (relationStr == "访友") {
		relationType = 4;
	} else if (relationStr == "学习") {
		relationType = 5;
	}
	return relationType;
}
function getPassportStr(passportValue) {
	var passportStr = "外交";
	if (passportValue == 2) {
		passportStr = "公务";
	} else if (passportValue == 3) {
		passportStr = "普通";
	} else if (passportValue == 4) {
		passportStr = "其他";
	}
	return passportStr;
}
function getProfessionValue(professionStr) {
	var professionValue = 0;
	if (professionStr == "在职") {
		professionValue = 1;
	} else if (professionStr == "无业") {
		professionValue = 2;
	} else if (professionStr == "学生") {
		professionValue = 3;
	} else if (professionStr == "退休") {
		professionValue = 4;
	} else if (professionStr == "学龄前儿童") {
		professionValue = 5;
	}
	return professionValue;
}
function getProfessionStr(professionValue) {
	var professionStr = "请选择";
	if (professionValue == 1) {
		professionStr = "在职";
	} else if (professionValue == 2) {
		professionStr = "无业";
	} else if (professionValue == 3) {
		professionStr = "学生";
	} else if (professionValue == 4) {
		professionStr = "退休";
	} else if (professionValue == 5) {
		professionStr = "学龄前儿童";
	}
	return professionStr;
}
function getEducationValue(professionStr) {
	var professionValue = 0;
	if(professionStr == "博士") {
		professionValue = 1;
	} else if (professionStr == "研究生") {
		professionValue = 2;
	} else if (professionStr == "本科") {
		professionValue = 3;
	} else if (professionStr == "大专") {
		professionValue = 4;
	} else if (professionStr == "高中") {
		professionValue = 5;
	} else if (professionStr == "初中") {
		professionValue = 6;
	} else if (professionStr == "小学") {
		professionValue = 7;
	}
	return professionValue;
}
function getEducationStr(professionValue) {
	var professionStr = "请选择";
	if (professionValue == 1){
	 	professionStr = "博士";
	} else if (professionValue == 2) {
		professionStr = "研究生";
	} else if (professionValue == 3) {
		professionStr = "本科";
	} else if (professionValue == 4) {
		professionStr = "大专";
	} else if (professionValue == 5) {
		professionStr = "高中";
	} else if (professionValue == 6) {
		professionStr = "初中";
	} else if (professionValue == 7) {
		professionStr = "小学";
	}
	return professionStr;
}
function getVisaDifficultyStr(difficultyValue) {
	var difficultyStr = "极易";
	if (difficultyValue == 1){
	 	difficultyStr = "容易";
	} else if (difficultyValue == 2) {
		difficultyStr = "一般";
	} else if (difficultyValue == 3) {
		difficultyStr = "困难";
	} 
	return difficultyStr;
}
//时间转换为星期几
function weekDate(date){
    var weekArray = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    return weekArray[date.getDay()]; 
}
//字符串转换为时间格式
function stringFromDate(dateString) { 
	if (dateString) { 
		var arr1 = dateString.split(" "); 
		var sdate = arr1[0].split('-'); 
		var date = new Date(sdate[0], sdate[1]-1, sdate[2]); 
		return date;
	} 
}
//计算两个时间相隔的天数
function DateMinus(date1,date2){//date1:小日期   date2:大日期
  　　var sdate = new Date(date1); 
  　　var now = new Date(date2); 
  　　var days = now.getTime() - sdate.getTime(); 
  　　var day = parseInt(days / (1000 * 60 * 60 * 24)); 
  　　return day; 
}
